package cn.train.controler;

import java.io.IOException;
import java.net.URLDecoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.train.model.Liulan;
import cn.train.model.UserTable;
import cn.train.service.HotWayServices;
import cn.train.service.UserTableService;
@WebServlet("/HotWayServlet")
public class HotWayServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String action = req.getParameter("action");
		String over = req.getParameter("over");
		String piaojia = req.getParameter("piaojia");
		UserTable usertable=new UserTable();
		Cookie[] cookies=req.getCookies();
		if(cookies!=null){
		for(int i=0;i<cookies.length;i++){
			Cookie cookie=cookies[i];
			System.out.println("开始取"+cookie.getName());
			if(cookie.getName().equals("uid")){				
				String ui= URLDecoder.decode(cookie.getValue(),"utf-8");
				int uid=Integer.parseInt(ui);
				usertable.setUid(uid);
				//name=cookie.getValue();
				
			}			
			if(cookie.getName().equals("uname")){				
				usertable.setUname(URLDecoder.decode(cookie.getValue(),"utf-8"));
				//name=cookie.getValue();
				UserTableService users=new UserTableService();
				usertable=users.getid(URLDecoder.decode(cookie.getValue(),"utf-8"));
				req.getSession().setAttribute("usertable", usertable);
			}
			
			
		}
		}
		
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String time1 = dateFormat.format(new java.util.Date());
		
		HotWayServices hws= new HotWayServices();
		List<Liulan> list=hws.findAll();
		
		req.setAttribute("list", list);
		req.setAttribute("time1", time1);
		req.getRequestDispatcher("font/index.jsp").forward(req, resp);
	}
	private String parseInt(String value) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
